package use_case.processRental;
import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;


import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;

import javax.swing.UIManager;

import use_case.handlereturns.ReturnUI;


public class RentalKioskUI {

	private JFrame frmMainMenu;
	private Ledger kioskLedger;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RentalKioskUI window = new RentalKioskUI();
					window.frmMainMenu.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/** 
	 * Create the application.
	 */
	public RentalKioskUI() {
		kioskLedger = new Ledger();
		initialize();
		
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmMainMenu = new JFrame();
		frmMainMenu.setTitle("Main Menu");
		frmMainMenu.getContentPane().setBackground(new Color(180, 0, 0));
		frmMainMenu.getContentPane().setLayout(null);
		
		JButton btnRent = new JButton("Rent");
		btnRent.setBackground(UIManager.getColor("Button.background"));
		btnRent.setFont(new Font("Tahoma", Font.BOLD, 18));
		btnRent.setBounds(60, 80, 100, 100);
		frmMainMenu.getContentPane().add(btnRent);
		btnRent.addActionListener(new RentListener());
		
		JButton btnReturn = new JButton("Return");
		btnReturn.setFont(new Font("Tahoma", Font.BOLD, 18));
		btnReturn.setBounds(220, 80, 100, 100);
		frmMainMenu.getContentPane().add(btnReturn);
		btnReturn.addActionListener(new ReturnListener());
		
		JButton btnLedger = new JButton("...");
		btnLedger.setFont(new Font("Tahoma", Font.BOLD, 18));
		btnLedger.setBounds(340, 220, 20, 20);
		frmMainMenu.getContentPane().add(btnLedger);
		btnLedger.addActionListener(new LedgerListener(frmMainMenu));
		
		
		
		JLabel lblTitle = new JLabel("Video Rental");
		lblTitle = new JLabel("Video Rental");
		lblTitle.setForeground(SystemColor.window);
		lblTitle.setFont(new Font("Tahoma", Font.BOLD, 24));
		lblTitle.setBounds(125, 13, 164, 41);
		
		
		SystemHealthLog.logSystemEvent("System startup.");
		
		frmMainMenu.getContentPane().add(lblTitle);
		frmMainMenu.setBounds(100, 100, 400, 300);
		frmMainMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmMainMenu.setVisible(true);
	}
	
	
	class LedgerListener implements ActionListener{
		private JFrame parent;
		public LedgerListener( JFrame parent )
		{
			this.parent = parent;
		}
		
		public void actionPerformed(ActionEvent event){
			AdminPanel adminPanel = new AdminPanel( parent, kioskLedger );
			adminPanel.setVisible( true );
		}
	}//close inner class
	
	class RentListener implements ActionListener{
		
		public void actionPerformed(ActionEvent event){
			frmMainMenu.setVisible(false);
			new RentUI(frmMainMenu,kioskLedger);
		}
	}//close inner class
	
	class ReturnListener implements ActionListener{
		
		public void actionPerformed(ActionEvent event){
			frmMainMenu.setVisible(false);
			new ReturnUI(frmMainMenu, kioskLedger);
		}
	}//close inner class	
}
